package small.common.core.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;


public class MapUtil {

    /**
     * 将非null值】放入map
     * @param target 目标map
     * @param key key
     * @param value 值
     */
    public static void putIfValNoNull(Map target, Object key, Object value) {
        Objects.requireNonNull(key, "key");
        if (value != null) {
            target.put(key, value);
        }
    }

    public static boolean isEmpty(Map map) {
        return (map == null || map.isEmpty());
    }
    /**
     * 将非null值】放入map
     * @param map 目标map
     */
    public static <T, V> HashMap<T,V> copyHashMap(Map<T,V> map) {
        HashMap<T,V> newMap = new HashMap<T,V>();
        if (isEmpty(map)){
            return newMap;
        }
        newMap.putAll(map);
        return newMap;
    }
}
